
ContractFormShow = Ext
		.extend(
				Ext.Window,
				{
					formPanel : null,
					constructor : function(a) {
						Ext.applyIf(this, a);
						this.initUIComponents();
						ContractFormShow.superclass.constructor.call(this, {
							layout : "fit",
							id : "ContractFormWin",
							title : "合同详细信息",
							iconCls : "menu-contract",
							width : 915,
							height : 500,
//							minWidth : 850,
//							minHeight : 550,
							
							items : this.formPanel,
							border : false,
							modal : true,
							plain : true,
							buttonAlign : "center",
							buttons : this.buttons
						});
					},
					initUIComponents : function() {
						
						dataa=[];
						vstore = new Ext.data.JsonStore({
							data:dataa,
							fields:["fileId","fileName","filePath"]
						});
						var e = new Ext.grid.CheckboxSelectionModel();
						msgrid1 = new Ext.grid.GridPanel({
							id:'contractFileNamePanel',
							store:vstore,
							height:177,
							autoScroll : true,
							sm : e,
							columns:[e,{header:"图片名称",dataIndex:"fileName",width:498}]
						});
						msgrid1.addListener("rowdblclick", function(c,
								f, d) {
							c.getSelectionModel().each(function(e) {
								FileUploadImageDetailForm.show(e.data.fileId);
							});
						});
						var b = __ctxPath + "/system/listDepartment.do";
						var a = new TreeSelector("serviceDepSelector", b,
								"维护部门", null);
						a.addListener("change", function() {
							Ext.getCmp("serviceDep").setValue(a.getValue());
						});						
						var c = new ContractConfigView();
						var cc=new ContractTechniqueView();
						
						this.formPanel = new Ext.FormPanel(
								{
									url : __ctxPath
											+ "/contract/saveContract.do",
									layout : "hbox",
									frame : false,
									layoutConfig : {
										padding : "5",
										pack : "start",
										align : "middle"
									},
									defaults : {
										margins : "0 5 0 5"
									},
									id : "ContractForm",
									frame : false,
									formId : "ContractFormId",
									defaultType : "textfield",
									autoScroll : true,
									items : [
											{
												xtype : "fieldset",
												title : "合同信息(带 * 号为必填)",
												layout : "form",
//												rowspan : 2,
												labelWidth : 80,
												defaultType : "textfield",
												width : 400,
												height : 680,
												defaults : {
													width : 280
												},
												items : [
														{
															name : "contract.contractId",
															id : "contractId",
															xtype : "hidden",
															value : this.contractId == null ? ""
																	: this.contractId
														},
														{
															xtype : "hidden",
															name : "contract.ctFilePath",
															id : "ctFilePath"
														},
														{
															fieldLabel : "合同编号*",
															name : "contract.contractNo",
															id : "contractNo",
															allowBlank : false,
															blankText : "合同编号不可为空!"
														},
														{
															fieldLabel : "合同标题*",
															name : "contract.contractName",
															id : "contractName",
															allowBlank : false,
															blankText : "合同标题不可为空!"
														},
														{
															xtype : "compositefield",
															fieldLabel : "合同金额*",
															items : [
																	{
																		xtype : "numberfield",
																		width : 230,
																		name : "contract.contractAmount",
																		id : "contractAmount",
																		allowBlank : false,
																		blankText : "合同金额不可为空!"
																	},
																	{
																		value : "元",
																		xtype:"displayfield",
																		width : 10,
																		
																		style : "padding-left:0px;padding-top:3px;"
																	} ]
														},
														
														{
															fieldLabel : "合同类型",
															xtype : "textfield",
															name : "contract.contractType",
															id : "contractType"
														},
														{
															fieldLabel : "项目编号",
															xtype : "textfield",
															name : "contract.projectNo",
															id : "projectNo"
														},
														{
															fieldLabel : "项目名称",
															xtype : "textfield",
															name : "contract.projectName",
															id : "projectName"
														},
														{
															fieldLabel : "主要条款",
															xtype : "textarea",
															name : "contract.mainItem",
															id : "mainItem"
														},
														{
															fieldLabel : "售后条款",
															xtype : "textarea",
															name : "contract.salesAfterItem",
															id : "salesAfterItem"
														},
														{
															xtype : "compositefield",
															fieldLabel : "起止日期*",
															items : [
																	{
																		xtype : "datefield",
																		width : 110,
																		format : "Y-m-d",
																		editable : true,
																		name : "contract.validDate",
																		id : "validDate",
																		allowBlank : false,
																		blankText : "合同生效日期不可为空!"
																	},
																	{
																		value : "至",
																		xtype : "displayfield",
																		width : 10,
																		style : "padding-left:0px;padding-top:3px;"
																	},
																	{
																		xtype : "datefield",
																		width : 110,
																		format : "Y-m-d",
																		editable : true,
																		name : "contract.expireDate",
																		id : "expireDate",
																		allowBlank : false,
																		blankText : "合同到期日期不可为空!"
																	} ]
														},
														{
															xtype : "compositefield",
															fieldLabel : "签定人*",
															items : [
																	{
																		xtype : "textfield",
																		width : 180,
//																		readOnly : true,
																		name : "contract.signupUser",
																		id : "signupUser",
																		editable : true,
																		allowBlank : false,
																		blankText : "签定人不可为空!"
																	},
																	{
																		xtype : "button",
																		text : "签定人",
																		iconCls : "btn-mail_recipient",
																		handler : function() {
																			UserSelector
																					.getView(
																							function(
																									e,
																									d) {
																								Ext
																										.getCmp(
																												"signupUser")
																										.setValue(
																												d);
																							},
																							true)
																					.show();
																		}
																	} ]
														},
														{
															fieldLabel : "签定时间",
															xtype : "datefield",
															format : "Y-m-d",
															editable : true,
															name : "contract.signupTime",
															id : "signupTime",
															allowBlank : false,
															blankText : "签定时间不可为空!"
														},
														{
															fieldLabel : "维护部门",
															name : "contract.serviceDep",															
															xtype : "hidden",
															id : "serviceDep"
																
														},
														a,
													
														
														
														{
															xtype : "compositefield",
															fieldLabel : "维护人*",
															items : [
																	{
																		xtype : "textfield",
																		width : 180,
//																		readOnly : true,
																		name : "contract.serviceMan",
																		editable : true,
																		id : "serviceMan"
																	},
																	{
																		xtype : "button",
																		text : "维护人",
																		iconCls : "btn-mail_recipient",
																		handler : function() {
																			UserSelector
																					.getView(
																							function(
																									e,
																									d) {
																								Ext
																										.getCmp(
																												"serviceMan")
																										.setValue(
																												d);
																							},
																							true)
																					.show();
																		}
																	} ]
														},

														
														
														{

															id : "displayContractAttach",
															xtype : "panel",
//															bodyStyle : "padding:0px;",
															title : "合同文件（双击可下载对应的图片）",
															width : 380,
															autoHeight : true,														
															border : false,
															items : msgrid1


														}
														
														
														]
											},
											{
												xtype : "container",
												style : "padding:5px 0px 0px 0px;",
												items : [
												         
														{
															xtype : "fieldset",
															title : "工艺文件信息",
															layout : "form",
//															labelWidth : 55,
															width : 465,
															autoHeight : true,
															style : "padding-bottom:0px;bottom:0px;",
															defaultType : "textfield",
															items : [
															         cc

																	
																	]
														},
														{
															xtype : "fieldset",
															title : "产品交付信息",
															layout : "form",
															width : 465,
															style : "padding-top:0px;top:0px;",
															autoHeight : true,
															labelWidth : 58,
															defaultType : "textfield",
															items : [
																	{
																		fieldLabel : "收货地址",
																		name : "contract.consignAddress",
																		id : "consignAddress",
																		width : 280
																	},
																	{
																		fieldLabel : "收货人",
																		name : "contract.consignee",
																		id : "consignee",
																		width : 280
																	}, c ]
														} ]
											} ]
								});
						if (this.contractId != null
								&& this.contractId != "undefined") {
							this.formPanel
									.getForm()
									.load(
											{
												deferredRender : false,
												url : __ctxPath
														+ "/contract/getContract.do?contractId="
														+ this.contractId,
												waitMsg : "正在载入数据...",
												success : function(e, g) {
													var p = g.result.data;

													if(p.ctFilePath){
														contractFormUploadUserPhoto(p.ctFilePath,1);
													}
													var h = getDateFromFormat(
															p.validDate,
															"yyyy-MM-dd HH:mm:ss");
													var d = getDateFromFormat(
															p.expireDate,
															"yyyy-MM-dd HH:mm:ss");
													var k = getDateFromFormat(
															p.signupTime,
															"yyyy-MM-dd HH:mm:ss");
													Ext
															.getCmp("validDate")
															.setValue(
																	new Date(h));
													Ext
															.getCmp(
																	"expireDate")
															.setValue(
																	new Date(d));
													Ext
															.getCmp(
																	"signupTime")
															.setValue(
																	new Date(k));
													Ext
															.getCmp(
																	"serviceDepSelector")
															.setValue(
																	p.serviceDep);

													
													var f = Ext
															.getCmp("contractId").value;
													if (f != null && f != ""
															&& f != "undefined") {
														var z = Ext
														.getCmp(
																"ContractTechniqueGrid")
														.getStore();
												z
														.reload({
															params : {
																"Q_contract.contractId_L_EQ" : f
															}
														});
														
														var n = Ext
																.getCmp(
																		"ContractConfigGrid")
																.getStore();
														n
																.reload({
																	params : {
																		"Q_contract.contractId_L_EQ" : f
																	}
																});
													}

												},
												failure : function(d, e) {
													Ext.ux.Toast.msg("编辑",
															"载入失败");
												}
											});
						}
						this.buttons = [ 

						{
							text : "关闭",
							iconCls : "btn-cancel",
							handler : function() {
								Ext.getCmp("ContractFormWin").close();
							}
						} ];
					}
				});

function contractFormUploadUserPhoto(b,j) {
	var a = Ext.getCmp("ctFilePath");
	try{var h=Ext.getCmp("contractId").getValue();}catch(e){}
	var c = Ext.getCmp("displayContractAttach"); 
	if(h==""&&j==1){
		for(var i in b){		
			if(b[i].filePath != undefined){
				 var RType=Ext.data.Record.create([
				                                {name:"fileId",type:"string"},
				                                {name:"fileName",type:"string"},
				                                {name:"filePath",type:"string"}
				                               ]);
				
				 var bf=new RType({fileId:b[i].fileId,fileName:b[i].fileName,filePath:b[i].filePath});
				 msgrid1.getStore().add(bf);
			}
		}
		 
	}else{
		if(msgrid1.getStore().getCount()==0){
			try{msgrid1.getStore().loadData(eval(a.getValue()),false);}catch(e){}
		  }
			 for(var i in b){ 
				 if(b[i].filePath != undefined){ 
					 var RType=Ext.data.Record.create([
					                                {name:"fileId",type:"string"},
					                                {name:"fileName",type:"string"},
					                                {name:"filePath",type:"string"}
					                               ]);
					
					 var bf=new RType({fileId:b[i].fileId,fileName:b[i].fileName,filePath:b[i].filePath});
					 var bff=new RType({fileName:b[i].fileName});
					 msgrid1.getStore().add(bf);										
				 }	
			}		
	 }
};


























